package com.itheima.threadDemo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建callable对象,线程开启需要执行call里面的call方法
        MyCallable mc = new MyCallable();
        //将mc传递到FutureTask中,想要多线程,不能让Thread继承一个FutTask对象要创建两个
        FutureTask<String> ft1 = new FutureTask<>(mc);
        FutureTask<String> ft2 = new FutureTask<>(mc);

        Thread t1 = new Thread(ft1);
        Thread t2 = new Thread(ft2);
        t1.start();
        t2.start();
        //获取返回值
        String s1 = ft1.get();
        String s2 = ft2.get();
        System.out.println(s1);
        System.out.println(s2);
    }
}
class MyCallable implements Callable<String>{

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 100; i++) {
            System.out.println("现场开启了" +i );
        }
        return "ok";
    }
}
